﻿@{
    Layout = null;
    var plugName = @brand.admin.cyt369.com.Areas.BrandAdmin.Models.PlugName.Name;
    var tableName = PageViewModel.PageTableID(this, plugName);
    var tableToolBar = PageViewModel.PageTableToolbar(this, plugName);
    var tableToolBarSearch = PageViewModel.PageTableToolbarSearch(this);
    var tableToolBarReset = PageViewModel.PageTableToolbarReset(this);
    var deleteFunName = PageViewModel.PageFunctionName(this, "delete_brand");

    var viewFunName = PageViewModel.PageFunctionName(this, "view_brand", plugName);
    var viewDlgName = PageViewModel.PageEditDialog(this, "view", plugName);

    var auditLogFunName = PageViewModel.PageFunctionName(this, "view_audit_log", plugName);
    var auditLogDlgName = PageViewModel.PageEditDialog(this, "audit_log_dlg", plugName);

    var brandFmtFun = PageViewModel.PageFunctionName(this, "brand_fmt", plugName);
    var auditLogFmtFun = PageViewModel.PageFunctionName(this, "audit_log_fmt", plugName);
    var imgFmtFun = PageViewModel.PageFunctionName(this, "img_fmt", plugName);
    var amountFmtFun = PageViewModel.PageFunctionName(this, "amount_fmt", plugName);
    var orderNumberFmtFun = PageViewModel.PageFunctionName(this, "orderNumber_fmt", plugName);
    var cityTypeFmtFun = PageViewModel.PageFunctionName(this, "cityType_fmt", plugName);
    var categoryIDFmtFun = PageViewModel.PageFunctionName(this, "CategoryID_fmt", plugName);

    var editFunName = PageViewModel.PageFunctionName(this, "edit", plugName);
    var editDlgName = PageViewModel.PageEditDialog(this, plugName);
    var saveEditFunName = PageViewModel.PageFunctionName(this, "save_edit", plugName);
}
<style>
    .brandImage {
        width: 130px;
        height: 80px
    }
</style>
<div style="height:100%">
    <script type="text/javascript">
        function @(viewFunName)(id) {
            var dlg = $dlg('@viewDlgName');
            dlg.dialog({
                title: '内容预览', width: 1000, height: 600,
                closed: false, cache: false, modal: true, maximizable: true, resizable: true, maximized: true,
                href: '~/@plugName/Brand/_ViewBrandDlg/' + id + '?dlg=@viewDlgName',
                onResize: function () {
                    $(this).dialog('center');
                }
            });
        }

        function @(auditLogFunName)(id) {
            var dlg = $dlg('@auditLogDlgName');
            dlg.dialog({
                title: '审核记录', width: 1000, height: 600,
                closed: false, cache: false, modal: true, maximizable: true, resizable: true, maximized: false,
                href: '~/@plugName/Brand/_AuditLogDlg/' + id + '?dlg=@auditLogDlgName',
                onResize: function () {
                    $(this).dialog('center');
                }
            });
        }
    </script>

    <script type="text/javascript">
        function @(editFunName)(id) {
            var dlg = $dlg('@editDlgName');
            dlg.dialog({
                title: '品牌类别编辑', width: 600, height: 300, closed: false, cache: false, modal: true, maximizable: false, resizable: false, maximized: false,
                href: '~/@plugName/Category/_EditCategory',
                onResize: function () { $(this).dialog('center'); },
                buttons: [
                    {
                        text: "保 存",
                        handler: function () { @(saveEditFunName)(); },
                        iconCls: "icon-save"
                    }, {
                        text: "取 消",
                        handler: function () { $("#@editDlgName").dialog("close"); },
                        iconCls: "icon-cancel"
                    }
                ],
                onLoad: function () {
                    LoadObject(id, "~/@plugName/Category/GetCategoryByID/", function (category) {
                        var form = $("#@editDlgName").find("form");
                        form.form("load", category);
                    });
                }
            });
        }



        function @(saveEditFunName)() {
            var form = $("#@editDlgName").find("form");
            if (form.form('enableValidation').form('validate')) {
                var category = form.form_to_json(function (form, category) {
                });
                $.ajax({
                    url: "~/@plugName/Category/SaveCategory",
                    type: "POST",
                    data: category,
                    success: function (e) {
                        if (e.Result) {
                            $.messager.alert('保存成功', '保存成功!', 'info', function () {
                                $('#@editDlgName').dialog('close');
                            });
                        } else {
                            $.messager.alert('保存失败', '保存失败: ' + e.Msg, 'error');
                        }
                    },
                    error: function (e) {
                        ShowAjaxError(e);
                    }
                });
            }
        }
    </script>

    <script type="text/javascript">
        function @tableToolBarSearch{
            $('#@tableName').datagrid('load', {
                Title: $("#@tableToolBar").find("#_Title").textbox("getValue"),
            });
        }

        function @tableToolBarReset{
            $("#@tableToolBar").find("#_Title").textbox("setValue", "");
        @(tableToolBarSearch)();
                                        }
    </script>

    <script type="text/javascript">
        function @(deleteFunName)(id) {
            if (id > 0 && confirm("确认删除内容?")) {
                $.ajax({
                    async: false,
                    method: "DELETE",
                    url: $.Content("~/@plugName/HotBrand/HotBrandDelete/" + id),
                    context: $("#@tableName"),
                    success: function (e) {
                        if (e.Result) {
                            this.datagrid('reload');
                        } else {
                            $.messager.alert('删除数据', '删除失败: ' + e.Msg, 'error');
                        }
                    },
                    error: function (e1, e2, e3) {
                        ShowAjaxError(e1, "删除数据");
                        this.datagrid('reload');
                    }
                });
            }
        }

        function @(imgFmtFun)(v, r, i){
            let result = ""
            let imgPath = "@Admin.CYT369.Com.Utility.SystemSettingService.Instance.BrandBucket.HttpURL" + "/" + r.ImagePath
            result = `<img src="${imgPath}" class="brandImage"></img>`;
            return result;
        }

        function @(amountFmtFun)(v, r, i){
            if (r.Amount == 1) { return "5万以下"; }
            else if (r.Amount == 2) { return "5~10万"; }
            else if (r.Amount == 3) { return "10~20万"; }
            else if (r.Amount == 4) { return "20~50万"; }
            else if (r.Amount == 5) { return "50~100万"; }
            else if (r.Amount == 6) { return "100以上"; }
            else { return ""; }
        }

        function @(orderNumberFmtFun)(v, r, i){
            return r.HotBrand.OrderNumber + "";
        }

        function @(brandFmtFun)(v, r, i) {
            return "<a href='javascript:@viewFunName (" + r.Brand.Id + ")'>" + r.Brand.Name + "</a>";
        }

        function @(auditLogFmtFun)(v, r, i) {
            return "<a href='javascript:@auditLogFunName (" + r.Id + ")'>审核记录</a>";
        }

        function @(categoryIDFmtFun)(v, r, i) {
            var v = GetObject(v, '~/@plugName/Category/GetCategoryByID');
            if (v != null) { return v.CategoryName; }
        }

        function @(cityTypeFmtFun)(v, r, i) {
            var v = GetObject(v, '~/@plugName/City/GetCityByID');
            if (v != null) { return v.CityName; }
        }


    </script>

    <table id="@tableName" class="easyui-datagrid" style="width:100%;" rownumbers="true" fit="true"
           pagination="true" pageSize="@SystemSettingService.Instance.PageSize" pageList="@SystemSettingService.Instance.PageList"
           data-options="striped:true,border:false,singleSelect:true,url:'~/@plugName/Carousel/GetsCarousel',method:'get',toolbar:'#@tableToolBar'">
        <thead>
            <tr>
                <th data-options="field:'_remove',align:'center',formatter:function(v,r,i){
                        return GridRowDeleteFmt('@deleteFunName', r.Id);
                    }" width="60">删除</th>
                <th data-options="field:'_img',formatter:@imgFmtFun" width="150">轮播图片</th>
                <th data-options="field:'_name',formatter:@brandFmtFun" width="300">品牌名称</th>
                <th data-options="field:'OrderNumber',align:'center'" width="200">顺序号</th>
                <th data-options="field:'Amount',align:'center',formatter:@amountFmtFun" width="200">是否启用</th>
            </tr>
        </thead>
    </table>
    <div id="@tableToolBar" class="table-toolbar">
        <ul class="query-body">
            <a href="javascript:@editFunName ()" class="easyui-linkbutton t-btn"><i class="fa fa-plus-circle" style="color:green"></i><span>新增</span></a>
        </ul>
    </div>
</div>